<?php

class Index extends App {
	
	public static function Init() {
		// Endup fonksiyonunun çıkışını direk çıkışa (std) ver 
		self::setTarget("std", "EndUp");
		
		Page::set("working.content", "çalışıyor");
		
		//$d = App::Call("wiki", "view", array("sidebar", "none"), "regular", "return");
		//if ($d) Page::Set("page.sidebar", $d['stdout']);
	}
	
	public static function StartUp() {
		global $conf;
		
		// Change these for your site
		Page::Set("page.title", "sample minf site", "set");
		meta_add_keywords("minf,php");
		meta_set_description("this is sample minf site");
		meta_set_author("MINF Team");
		
		// DO NOT CHANGE ANYTHING BELOW (if you do not need to)
		echosys("INDEX: Getting Up (starting session)", MSG_NOTICE);
		session_start();
		echosys("INDEX: Connecting to Mysql", MSG_NOTICE);
		if (!DB::Connect($conf['db'])) echosys("MySQL: Cannot connect to database server", MSG_ERROR);
		if (!DB::SelectDB($conf['db']['database'])) echosys("MySQL: Cannot select database ({$conf['db']['database']}) ", MSG_ERROR);
		DB::SetUTF8();
		if (mysql_error()) echosys("MySQL: ".mysql_error(), MSG_ERROR);
		if ($qq = get_file("initial.sql")) {
			if (DB::Query($qq)) {
				del_file("initial.sql");
				echosys("MySQL: Executed Initial SQL", MSG_NOTICE);
			}else{
				echosys("MySQL: Cannot Execute Initial SQL", MSG_ERROR);	
			}
		}
	}
	
	public static function NotFound () {
		header("HTTP/1.1 404 Not Found");
		echo "<span class='information error'>Böyle bir sayfa yok</span>";		
	}
	
	public static function NoPermission () {
		header("HTTP/1.1 403 Forbidden");
		echo "<span class='information warning'>Bu sayfayı görmek için yetkiniz yok</span>";
	}
	
	public static function Homepage () {
		echo "hello world! this is the index page";
	}
	
	public static function Endup () {
		// LAST STUFF TO DO BEFORE DEATH (eg. rendering main template)
		global $master_template;
		meta_register();
		if (!$master_template||strlen($master_template)<5) $master_template = "index.tpl";
		echo smarty_render($master_template);
	}
	
}

?>